﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Data.SqlClient;
using System.Threading;
using System.IO;
using System.Reflection;


namespace AMix
{
    public partial class DocAmixFrm : FrmCard
    {
        public int LunaCurenta = 0;
        public int AnulCurent = 0;
        public String NrInventar = String.Empty;
        private Boolean BlockCorelations = true;
        private String SerieNumerica = String.Empty;
        /// <summary>
        /// numarul de inregistrari adaugate
        /// </summary>
        private Int32 NoRecAdd = 0;
        private Int32 codDoc = -1;

        public DocAmixFrm(Int32 CodDoc, ModuleClass mInfo)
            : base(mInfo)
        {
            codDoc = CodDoc;
            InitializeComponent();
            workConnString = mInfo.workConnectionString;
            this.HandleAfterAdd += new AfterAddHandler(DocAmixFrm_HandleAfterAdd);
            this.HandleRezumat += new EventHandler(DocAmixFrm_HandleRezumat);
            eSRPDataSet.AmixDocumente.CodUnitateColumn.DefaultValue = ModuleInfo.CodUnitate;
            regimuriAmortizareBindingSource.List.Add(new RegimuriAmortizare("Fara Amortizare", 0));
            regimuriAmortizareBindingSource.List.Add(new RegimuriAmortizare("Liniar", 1));
            regimuriAmortizareBindingSource.List.Add(new RegimuriAmortizare("Degresiv", 2));
            regimuriAmortizareBindingSource.List.Add(new RegimuriAmortizare("Accelerat", 3));

            TipMijlocFixBindingSource.List.Add(new RegimuriAmortizare("Mijloc Fix", 0));
            TipMijlocFixBindingSource.List.Add(new RegimuriAmortizare("Mijloc Fix Compus", 1));
            TipMijlocFixBindingSource.List.Add(new RegimuriAmortizare("Mijloc Fix Componenta", 2));
            TipMijlocFixBindingSource.List.Add(new RegimuriAmortizare("Obiect de Inventar", 3));
            TipMijlocFixBindingSource.List.Add(new RegimuriAmortizare("Seturi Obiecte de Inventar", 4));

            eSRPDataSet.AmixDocumente.DataDocColumn.DefaultValue = DateTime.Now;
            eSRPDataSet.AmixDocumente.PunereInFunctiuneColumn.DefaultValue = DateTime.Now;
            eSRPDataSet.AmixDocumente.RegimAmortizareColumn.DefaultValue = 1;
            eSRPDataSet.AmixDocumente.ValoareInventarColumn.DefaultValue = 0.0;
            eSRPDataSet.AmixDocumente.AmortizareAnColumn.DefaultValue = 0.0;
            eSRPDataSet.AmixDocumente.AmortizareLunaColumn.DefaultValue = 0.0;
            eSRPDataSet.AmixDocumente.DurExtindereColumn.DefaultValue = 0;
            eSRPDataSet.AmixDocumente.ComisiaRecColumn.DefaultValue = String.Empty;
            eSRPDataSet.AmixDocumente.DurataAmortizareColumn.DefaultValue = 0;
            eSRPDataSet.AmixDocumente.ValoareAmortizataColumn.DefaultValue = 0;
            eSRPDataSet.AmixDocumente.ValoareSuplimentaraColumn.DefaultValue = 0;
            eSRPDataSet.AmixDocumente.LuniAmortizateColumn.DefaultValue = 0;
            eSRPDataSet.AmixDocumente.CantitateOIColumn.DefaultValue = 1;
            eSRPDataSet.AmixDocumente.InFolosintaColumn.DefaultValue = true;
            eSRPDataSet.AmixDocumente.IdClasificareColumn.DefaultValue = 0;
            eSRPDataSet.AmixDocumente.IDGestionarColumn.DefaultValue = 0;
            numeMacheta = Text;

            dataDocDTP.Format = DateTimePickerFormat.Custom;
            dataDocDTP.CustomFormat = "dd.MM.yyyy";
            PunereInFunctiuneDTP.Format = DateTimePickerFormat.Custom;
            PunereInFunctiuneDTP.CustomFormat = "dd.MM.yyyy";
            HandlerValidatingAfterEndEdit += DocAmixFrm_HandlerValidatingAfterEndEdit;
           
        }

        bool DocAmixFrm_HandlerValidatingAfterEndEdit(object sender)
        {
            
            ESRPDataSet.AmixDocumenteDataTable dt = eSRPDataSet.AmixDocumente.GetChanges() as ESRPDataSet.AmixDocumenteDataTable;
            if (dt == null)
                return true;
            foreach (ESRPDataSet.AmixDocumenteRow dr in dt.Rows)
            {
                if (dr.RowState == DataRowState.Deleted)
                    continue;

                Int16 tipDoc = dr.IDTipDocument;
                if (dr.NrInventar == String.Empty && tipDoc >= 2)
                {
                    errorProvider1.SetError(nrInventarTB, "Numarul de inventar este o informatie obligatorie pentru un mijloc fix." + dr.NrInventar);
                    MessageBoxFrm mbt = new MessageBoxFrm("Eroare validare", "Numarul de inventar este o informatie obligatorie pentru un mijloc fix." + nrInventarTB.Text, String.Empty, MessageBoxFrm.ImaginiMB.StopIcon, amixDocumenteBindingSource.Current);
                    mbt.AddButton("Ieşire", 70, mbt.MessageBoxFrm_Click_Yes);
                    mbt.ShowDialog();
                    return false;
                }

                int poz = amixRegistruBindingSource.Find("NrInventar", dr.NrInventar);
                // pentru toate documentele cu exceptia intrarii
                if (poz == -1 && tipDoc > 2)
                {
                    errorProvider1.SetError(nrInventarTB, "Numarul de inventar inexistent:" + dr.NrInventar);
                    MessageBoxFrm mbt = new MessageBoxFrm("Eroare validare", "Numarul de inventar inexistent:" + dr.NrInventar, String.Empty, MessageBoxFrm.ImaginiMB.StopIcon, amixDocumenteBindingSource.Current);
                    mbt.AddButton("Ieşire", 70, mbt.MessageBoxFrm_Click_Yes);
                    mbt.ShowDialog();
                    return false;
                }


                amixRegistruBindingSource.Position = poz;
                ESRPDataSet.AmixRegistruRow arr = ((DataRowView)amixRegistruBindingSource.Current).Row as ESRPDataSet.AmixRegistruRow;

                if (dr.IDTipDocument > 2 && arr.IDStare == 2 && dr.RowState == DataRowState.Added)
                {
                    errorProvider1.SetError(nrInventarTB, "Atentie: Mijlocul fix inexistent sau iesit - va rugam introduceti un numar de inventar valid! :" + nrInventarTB.Text);
                    MessageBoxFrm mbt = new MessageBoxFrm("Eroare", "Atentie: Mijlocul fix inexistent sau iesit - va rugam introduceti un numar de inventar valid! :" + nrInventarTB.Text, String.Empty, MessageBoxFrm.ImaginiMB.StopIcon, dr);
                    mbt.AddButton("Iesire", 70, mbt.MessageBoxFrm_Click_Yes);
                    mbt.ShowDialog();
                    return false;
                }
            }
            return true;
        }

        void DocAmixFrm_HandleRezumat(object sender, EventArgs e)
        {
            DocRezumatFrm frm = new DocRezumatFrm(ModuleInfo,(short)LunaCurenta,(short)AnulCurent,MijloaceFixeRB.Checked);
            frm.SelectionAddOn = true;
            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (frm.selectedDataRow != null)
                {
                    amixDocumenteBindingSource.RemoveFilter();
                    ESRPDataSet.AmixDocumenteRow pr = frm.selectedDataRow.Row as ESRPDataSet.AmixDocumenteRow;
                    amixDocumenteBindingSource.Position = amixDocumenteBindingSource.Find("IDMijlocFix", pr.IDMijlocFix);
                    amixDocumenteBindingSource.ResetCurrentItem();
                }
            }
            EnableMainBrowseButton = true;
        }

        void DocAmixFrm_HandleAfterAdd(object sender, DataGridViewCellEventArgs args)
        {
            if (SerieNumerica == String.Empty)
                return;
            String valnew = "1";
            SqlCommand cmd = new SqlCommand("", DeschideConexiune(workConnString));
            cmd.CommandText = "SELECT [UltimulNrFolosit] FROM [SeriiNumerice] WHERE IDSerie='" + SerieNumerica + "' AND [CodUnitate]=" + ModuleInfo.CodUnitate.ToString();
            Object ret = cmd.ExecuteScalar();
            if (ret != null && ret != DBNull.Value)
            {
                valnew = ret.ToString();
            }
            ///incrementarea seriei se face la salvare
            ///
            if (NoRecAdd > 0)
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "amix_ActSeriiNumerice";
                cmd.Parameters.Add(new SqlParameter("IDSerie", SerieNumerica));
                cmd.Parameters.Add(new SqlParameter("CodUnitate", ModuleInfo.CodUnitate));
                cmd.ExecuteNonQuery();
                NoRecAdd--;
            }
            else
                NoRecAdd++;
            InchideConexiune(cmd.Connection);
            if (tipDocCB.SelectedValue!=null && Convert.ToInt16(tipDocCB.SelectedValue) == 2)
                this.nrInventarTB.Text = valnew;
            ActiveControl = tipDocCB;
        }

        private void DocAmixFrm_Load(object sender, EventArgs e)
        {
            SqlConnection con = DeschideConexiune(workConnString);
            this.surseFinantareTableAdapter.Connection = con;
            this.surseFinantareTableAdapter.Fill(this.eSRPDataSet.SurseFinantare);
            this.amixGestionariTableAdapter.Connection = con;
            this.unitatiMasuraTableAdapter.Connection = con;
            this.unitatiMasuraTableAdapter.Fill(this.eSRPDataSet.UnitatiMasura);
            this.amixGestionariTableAdapter.Fill(this.eSRPDataSet.AmixGestionari);
            amixRegistruTableAdapter.Connection = con;
            amixRegistruTableAdapter.Fill(eSRPDataSet.AmixRegistru, ModuleInfo.CodUnitate, (short)(MijloaceFixeRB.Checked ? 0 : 3), (short)(MijloaceFixeRB.Checked ? 2 : 5));
            amixTipModDocumentTableAdapter.Connection = con;
            amixTipModDocumentTableAdapter.FillAll(this.eSRPDataSet.AmixTipModDocument);
            this.conturiTableAdapter.Connection = con;
            this.conturiTableAdapter.FillByTerminal(this.eSRPDataSet.Conturi,ModuleInfo.CodUnitate);

            departamenteTableAdapter.Connection = con;
            departamenteTableAdapter.Fill(eSRPDataSet.Departamente, ModuleInfo.CodUnitate);
            this.amixCatalogTableAdapter.Connection = con;
            this.amixCatalogTableAdapter.Fill(this.eSRPDataSet.AmixCatalog);
            this.viewDocumenteInModuleTableAdapter.Connection = con;

            #region Citeste tipurile de documente permise in modul
            //[admin_ApplicationDocuments] 'F9B96690-0736-4F91-BC2C-F434651A1AFF'
            SqlCommand cmd = new SqlCommand("SELECT * FROM [admin_ApplicationDocuments] WHERE [ApplicationID]='" + ModuleInfo.ApplicationID.ToString() + "'",
                DeschideConexiune("AdminConnectionString"));
            SqlDataReader dr1 = cmd.ExecuteReader();
            String filtDoc = String.Empty;
            while (dr1.Read())
            {
                if (filtDoc != String.Empty)
                    filtDoc += ",";
                filtDoc += dr1["IdTipDocument"].ToString();
            }
            dr1.Close();
            InchideConexiune(cmd.Connection); 
            #endregion

            this.viewDocumenteInModuleTableAdapter.Fill(this.eSRPDataSet.ViewDocumenteInModule);
            this.viewDocumenteInModuleTableAdapter.Adapter.SelectCommand.CommandText += " WHERE [IDTipDocument] in (" + filtDoc + ")";
            this.viewDocumenteInModuleTableAdapter.Fill(this.eSRPDataSet.ViewDocumenteInModule);
            this.amixDocumenteTableAdapter.Connection = con;
            if (codDoc != -1)
            {
                //deschide un singur document
                this.amixDocumenteTableAdapter.FillByOne(this.eSRPDataSet.AmixDocumente, ModuleInfo.CodUnitate, codDoc);
            }
            else
                this.amixDocumenteTableAdapter.Fill(this.eSRPDataSet.AmixDocumente,ModuleInfo.CodUnitate,
                    (short)(MijloaceFixeRB.Checked?0:3),(short)(MijloaceFixeRB.Checked?2:5));

            if (viewDocumenteInModuleBindingSource.Count == 0)
            {
                MessageBox.Show("Nu au fost definite tipurile de documente!",
                        "Eroare",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Stop);
                Close();
            }
            if (viewDocumenteInModuleBindingSource.Current != null)
            {
                Int16 tipD = Convert.ToInt16(((DataRowView)viewDocumenteInModuleBindingSource.Current)["IDTipDocument"]);
                eSRPDataSet.AmixDocumente.IDTipDocumentColumn.DefaultValue = tipD;
                if (tipD < 4)
                    amixTipModDocumentBindingSource.Filter = "IDTipDocument=" + tipD.ToString();
            }
            if (amixTipModDocumentBindingSource.Count != 0 && modCB.SelectedValue!=null)
            {
                eSRPDataSet.AmixDocumente.IDModColumn.DefaultValue = modCB.SelectedValue;                
            }
            Setup(con);
            InchideConexiune(con);

            if (codDoc != -1 && codDoc != -2)
            {
                ///daca deschide document din arhiva atunci 
                ///macheta este doar in citire
                DataRowView dr = ((DataRowView)amixDocumenteBindingSource.Current);
                Int32 lunaDoc = Convert.ToInt32(dr["Luna"]);
                Int32 anDoc = Convert.ToInt32(dr["Anul"]);
                if (anDoc * 100 + lunaDoc < AnulCurent * 100 + LunaCurenta)
                {
                    panelConturi.Enabled = false;
                    flowLayoutPanel1.Enabled = false;
                    modP.Enabled = false;
                    ReadOnly = true;
                }
                nrInventarTB_Leave(this, null);
                
            }

            AddButton("Componente", global::ERPStudio.Properties.Resources.clipboard, MFix_Componente, ToolStripItemAlignment.Right, true);
            HandleSalvare += new EventHandler(Salvare);
            this.listBndSourceMain.Add(amixDocumenteBindingSource);
            listTableAdaptor.Add(amixDocumenteTableAdapter.Adapter);

            SetTitle();

            if (amixDocumenteBindingSource.Count == 0 || codDoc == -2)
            {
                Adauga();
                if (NrInventar != String.Empty)
                {
                    tipDocCB.SelectedValue = 3; //iesire
                    ((DataRowView)amixDocumenteBindingSource.Current)["IDTipDocument"] = 3;
                    nrInventarTB.Text = NrInventar;
                    nrInventarTB_Leave(this, null);

                }
            }
            BlockCorelations = false;
            
        }

        private void Setup(SqlConnection wConn)
        {

            Object ret = GetSetupValue("AmixSetup", "LunaCurenta", ModuleInfo.CodUnitate, wConn);
            if (ret != null && ret != DBNull.Value)
                LunaCurenta = (Int16)ret;
            else
            {
                while (ret == null)
                {
                    MessageBox.Show("Modulul Amix nu a fost configurat. \nVa rugam sa-l configurati!",
                            "Eroare",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Hand);
                    AmixSetupFrm frm = new AmixSetupFrm(ModuleInfo);
                    frm.ShowDialog();
                    ret = GetSetupValue("AmixSetup", "LunaCurenta", ModuleInfo.CodUnitate, wConn);
                }
            }
            LunaCurenta = (Int16)ret;
            Object retObj = GetSetupValue("AmixSetup", "AnulCurent", ModuleInfo.CodUnitate, wConn);
            if (retObj != null && retObj != DBNull.Value)
                AnulCurent = Convert.ToInt32(retObj);

            
            if (LunaCurenta == 0)
            {
                MessageBox.Show("Modulul Amix nu a fost configurat corect (Luna curenta=0). \nVa rugam sa-l configurati!",
                            "Eroare",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Hand);
                return;
            }

            ///daca este in perioada curenta
            ///
            retObj = GetSetupValue("AmixSetup", "IDSerieInventar", ModuleInfo.CodUnitate, wConn);
            if (retObj != null && retObj != DBNull.Value)
                SerieNumerica = retObj.ToString();

            if (ModuleInfo.AnArhiva == String.Empty && (codDoc == -1 || codDoc == -2))
            {
                amixDocumenteBindingSource.Filter = "[DataDoc] >= '" + AnulCurent.ToString() + "-" + LunaCurenta.ToString() + "-1'";

                dataDocDTP.MinDate = new DateTime(AnulCurent, LunaCurenta, 1);
                //PunereInFunctiuneDTP.MinDate = new DateTime(AnulCurent, LunaCurenta, 1);
                //PunereInFunctiuneDTP.MinDate = PunereInFunctiuneDTP.MinDate.AddMonths(-1);
                eSRPDataSet.AmixDocumente.DataDocColumn.DefaultValue = dataDocDTP.MinDate;
                eSRPDataSet.AmixDocumente.PunereInFunctiuneColumn.DefaultValue = dataDocDTP.MinDate; 
                eSRPDataSet.AmixDocumente.LunaColumn.DefaultValue = LunaCurenta;
                eSRPDataSet.AmixDocumente.AnulColumn.DefaultValue = AnulCurent;
                SetInfoLunaAnul(LunaCurenta.ToString() + "," + AnulCurent.ToString());
            }
            if (regimAmortizareCB.SelectedValue != null)
            {
                ProcentP.Visible = Convert.ToInt32(regimAmortizareCB.SelectedValue) == 3;
                if (Convert.ToInt32(regimAmortizareCB.SelectedValue) == 3)
                {

                    if (valoareInventarTB.Text != String.Empty && AmortizareAnTB.Text!=String.Empty)
                    {
                        Decimal vi  =  Convert.ToDecimal(valoareInventarTB.Text);
                        Decimal aa = Convert.ToDecimal(AmortizareAnTB.Text);
                        if(vi!=Decimal.Zero)
                            ProcentNUD.Text = ((aa * 100) / vi).ToString();
                    }
                }
            }
            if (modCB.SelectedValue != null)
            {
                Int32 val =Convert.ToInt32(modCB.SelectedValue);
                ValoareAmortizataP.Visible = (val == 2) || (val == 8);
                ContTransferP.Visible = (val == 2);
            }

            //determina primul departament
            #region determina Departamentul implicit
            SqlCommand comm = new SqlCommand(String.Empty,wConn);
            comm.CommandText = "SELECT MIN(IDDepartament) FROM Departamente WHERE CodUnitate=" + ModuleInfo.CodUnitate.ToString();
            comm.CommandType = CommandType.Text;
            Object retu = comm.ExecuteScalar();
            Int32 idDep = 0;
            if (retu != null && retu != DBNull.Value)
                idDep = Convert.ToInt32(retu);
            else
            {
                MessageBoxFrm mbt = new MessageBoxFrm("Mesaj", "Va rugăm adăugați cel puțin un departament(loc de funcționare)!", String.Empty, MessageBoxFrm.ImaginiMB.StopIcon, null);
                mbt.AddButton("Iesire", 70, mbt.MessageBoxFrm_Click_Yes);
                mbt.ShowDialog();
                return;
            }
            eSRPDataSet.AmixDocumente.IDDepartamentColumn.DefaultValue = idDep;

            #endregion

        }

        /// <summary>
        /// tipul de document
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tipDocCB.SelectedValue == null)
                return;
            Int16 valnoua = Convert.ToInt16(tipDocCB.SelectedValue);
            if (amixTipModDocumentBindingSource.Current!=null && valnoua < 4)
            {
                amixTipModDocumentBindingSource.Filter = "IDTipDocument=" + valnoua.ToString();
                eSRPDataSet.AmixDocumente.IDModColumn.DefaultValue = ((DataRowView)amixTipModDocumentBindingSource.Current)["IDMod"];
                modP.Visible = true;
            }
            else
                modP.Visible = false;

            Int16 tipDoc = Convert.ToInt16(tipDocCB.SelectedValue);
            Int16 tipOb = Convert.ToInt16(CompusCB.SelectedValue);
            mijlocFixGB.Visible = tipDoc == 2 || tipDoc == 3 || tipDoc == 4 || tipDoc == 5 || tipDoc == 6 || (tipDoc == 7) || (tipDoc == 8);
            DocumentGB.Visible = tipDoc == 2 || tipDoc == 3 || tipDoc == 4 || tipDoc == 5 || tipDoc == 6 || tipDoc == 7 || tipDoc == 8;
            ValoriGB.Visible = (tipDoc == 2 && tipOb!=3) || (tipDoc == 7) || (tipDoc == 8);
            ValoriGB.Enabled = (tipDoc != 8);
            LocFunctionareGB.Visible = tipDoc == 2 || tipDoc == 4;
            PunereInFunctiuneL.Visible = (tipDoc == 2) || tipDoc == 6;
            PunereInFunctiuneDTP.Visible = (tipDoc == 2 || tipDoc == 6);
            DurataAmortizareGB.Enabled = (tipDoc == 2) || (tipDoc == 7);
            CompusCB.Enabled = (tipDoc == 2) || (tipDoc == 7);
            denumireTB.Enabled = (tipDoc == 2) || (tipDoc == 7);
            ClasificareCB.Enabled =(tipDoc == 2) || (tipDoc == 7);
            ClasificareCB1.Enabled = (tipDoc == 2) || (tipDoc == 7);
            modernizareP.Visible = tipDoc == 8;
            ValoareInventarNUD.Visible = tipDoc > 2;
            ValoareInventarL.Visible = tipDoc > 2;
            ValoareRamasaNUD.Visible = tipDoc > 2;
            ValoareRamasaL.Visible = tipDoc > 2;
            ValoareAmortizataP.Visible = (tipDoc == 8);
            ValoareAmortizataP.Enabled = (tipDoc != 8);
            DataRowView dr = ((DataRowView)amixDocumenteBindingSource.Current);
            if (dr.IsNew)
            {
                //if (tipDoc == 8 || tipDoc == 7 || tipDoc == 6 || tipDoc == 5 || tipDoc == 3) //modernizare sau modificare mf
                //{
                dr["IDDepartament"] = 0;
                dr["IDGestionar"] = 1;
                if (tipDoc == 8)
                {
                    PunereInFunctiuneDTP.Value = new DateTime(AnulCurent, LunaCurenta, 1);
                }
                //}
                //else
                //{
                //    dr["IDDepartament"] = DBNull.Value;
                //    dr["IDGestionar"] = DBNull.Value;
                //}
            }
        }

        public void MFix_Componente(object sender, EventArgs args)
        {
            Salvare(sender,args);
            if (EroareSalvare)
                return;
            if (CompusCB.SelectedValue == null)
                return;
            if (Convert.ToInt16(CompusCB.SelectedValue) != 1)
            {
                MessageBox.Show("Mijlocul fix curent nu este un mijloc compus!",
                            "Eroare",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Hand);
                return;
            }
            if (Convert.ToInt16(tipDocCB.SelectedValue) > 2)
                return;
            ESRPDataSet.AmixDocumenteRow dr = ((DataRowView)amixDocumenteBindingSource.Current).Row as ESRPDataSet.AmixDocumenteRow;
            if (dr == null)
            {
                MessageBox.Show("Mijlocul fix curent nu s-a salvat!",
                            "Eroare",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Hand);
                return;
            }
            ComponenteMFixFrm frm = new ComponenteMFixFrm(dr.IDMijlocFix,ModuleInfo);
            frm.LunaCurenta = LunaCurenta;
            frm.AnulCurent = AnulCurent;
            frm.IDDocument = Convert.ToInt32(dr["IDDocument"]);
            frm.ShowDialog();
        }

        override public void Salvare(object sender, EventArgs args)
        {
            Cursor.Current = Cursors.WaitCursor;
           
            base.Salvare(this, args);
            SqlConnection con = DeschideConexiune(workConnString);
            int savePos = 0;
            if (EroareSalvare)
                return;

            tipDocCB.Enabled = false;
            if (NoRecUpdated > 0)
            {
                SqlCommand cmd = new SqlCommand("[amix_InchideLuna2]", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Luna", LunaCurenta.ToString()));
                cmd.Parameters.Add(new SqlParameter("@An", AnulCurent.ToString()));
                cmd.Parameters.Add(new SqlParameter("@CodUnitate", ModuleInfo.CodUnitate.ToString()));
                if (NoRecUpdated == 1 && amixDocumenteBindingSource.Current!=null)
                    cmd.Parameters.Add(new SqlParameter("@IDDocument",((DataRowView)amixDocumenteBindingSource.Current)["IDDocument"].ToString()));
                else
                    cmd.Parameters.Add(new SqlParameter("@IDDocument", "0"));
                cmd.Parameters.Add(new SqlParameter("@InchideLuna", "0"));
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch(Exception ex)
                {
                    TrateazaExceptie(ex);
                }

            }
            if (SerieNumerica != String.Empty)
                if (NoRecAdd > 0)
                {
                    SqlCommand cmd = new SqlCommand("", DeschideConexiune(workConnString));
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "amix_ActSeriiNumerice";
                    cmd.Parameters.Add(new SqlParameter("IDSerie", SerieNumerica));
                    cmd.Parameters.Add(new SqlParameter("CodUnitate", ModuleInfo.CodUnitate));
                    cmd.ExecuteNonQuery();
                    InchideConexiune(cmd.Connection);
                    NoRecAdd = 0;

                }

            Cursor.Current = Cursors.Default;
            if (NrInventar != String.Empty)
                this.Close();
        }

        private decimal GetCoefDegresiv(decimal perioada)
        {
            Decimal ret = Decimal.One;
            if (perioada >= 2 && perioada <= 5)
                ret =  1.5M;
            if (perioada > 5 && perioada <= 10)
                ret =  2;
            if (perioada > 10 )
                ret =  2.5M;
            return ret;
        }

        private void regimAmortizareCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            ValoareInventarTB_Validated(sender,e);
            ///setare vizibilitate pentru campurile fara amortizare
            ///
            CompusCB_SelectedIndexChanged(sender, e);
        }

        private void modCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            ESRPDataSet.AmixDocumenteRow adr = ((DataRowView)amixDocumenteBindingSource.Current).Row as ESRPDataSet.AmixDocumenteRow;
            if (adr == null)
                return;
            ValoareAmortizataP.Visible = (adr.IDMod == 2 || adr.IDMod == 3);
            ContTransferP.Visible = (adr.IDMod == 2);
           
            if (!ValoareAmortizataP.Visible && adr.RowState== DataRowState.Added)
                ValoareAmortizataNUD.Text = Decimal.Zero.ToString();

        }

        private void AmortizareAnTB_Leave(object sender, EventArgs e)
        {
            if (amixDocumenteBindingSource.Current == null)
                return;
            ESRPDataSet.AmixDocumenteRow adr = ((DataRowView)amixDocumenteBindingSource.Current).Row as ESRPDataSet.AmixDocumenteRow;
            /// daca nu s-a modificat nimic
            if (!BlockCorelations)
            {
                adr.AmortizareLuna = adr.AmortizareAn / 12;
                adr.AmortizareLuna = Decimal.Round(adr.AmortizareLuna,2);
                AmortizareLunaTB.Text = adr.AmortizareLuna.ToString();
            }
        }

        private void AmortizareLunaTB_Leave(object sender, EventArgs e)
        {
            if (!BlockCorelations)
            {
                ESRPDataSet.AmixDocumenteRow adr = ((DataRowView)amixDocumenteBindingSource.Current).Row as ESRPDataSet.AmixDocumenteRow;
                Decimal aa = adr.AmortizareLuna * 12;
                aa = Decimal.Round(aa, 2);
                Decimal bb = Convert.ToDecimal(AmortizareAnTB.Text);
                if(bb!=aa)
                    AmortizareAnTB.Text = aa.ToString();
            }
        }

        override public void toolStripLabelAnLuna_Click(object sender, EventArgs e)
        {
            Salvare();
            AmixSetupFrm frm = new AmixSetupFrm(ModuleInfo);
            frm.ShowDialog();
            this.OnActivated(null);
            ///actualizare unitate la copi
            foreach (Form frmChild in this.MdiParent.MdiChildren)
            {
                //if (frmChild != this)
                ((StudioForm)frmChild).SetCurentMonth(ModuleInfo.CodUnitate);
            }
        }

        override public void SetCurentMonth(short vCodUnitate)
        {
            SqlConnection con = DeschideConexiune(workConnString);
            Setup(con);
            InchideConexiune(con);
        }

        private Boolean block = false;

        private void durataAmortizareNUD_ValueChanged_1(object sender, EventArgs e)
        {
            ValoareInventarTB_Validated(sender, e);
            if (block || !durataAmortizareNUD.Visible)
                return;
            block = true;
            ////aici nu se modifica nici un control cu bind
            DurataAmortizareAniNUD.Value = Decimal.Round(Convert.ToDecimal(durataAmortizareNUD.Text) / 12,0);
            DurataAmortizareLuniNUD.Value = Convert.ToDecimal(durataAmortizareNUD.Text) % 12;
            block = false;
            
        }

        private void DurataAmortizareLuniNUD_ValueChanged(object sender, EventArgs e)
        {
            if (block || !DurataAmortizareLuniNUD.Visible || !DurataAmortizareAniNUD.Visible 
                || !DurataAmortizareLuniNUD.Enabled || !DurataAmortizareAniNUD.Enabled)
                return;
            Decimal valnoua = DurataAmortizareAniNUD.Value * 12 + DurataAmortizareLuniNUD.Value;
            block = true;
            if (Convert.ToDecimal(durataAmortizareNUD.Text)!=valnoua)
                durataAmortizareNUD.Text = valnoua.ToString();
            block = false;
            ValoareInventarTB_Validated(sender, e);
        }

        private void CompusCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (CompusCB.SelectedValue == null)
                return;
            Int16 tipVal = Convert.ToInt16(CompusCB.SelectedValue);
            regimAmortizareCB.Enabled = (tipVal != 1);
            durataAmortizareNUD.Enabled = (tipVal != 1) && (Convert.ToInt16(regimAmortizareCB.SelectedValue) != 0);
            valoareInventarTB.Enabled = (tipVal != 1) && (Convert.ToInt16(regimAmortizareCB.SelectedValue) != 0);
            AmortizareAnTB.Enabled = (tipVal != 1) && (Convert.ToInt16(regimAmortizareCB.SelectedValue) != 0);
            AmortizareLunaTB.Enabled = (tipVal != 1) && (Convert.ToInt16(regimAmortizareCB.SelectedValue) != 0);
            ValoareAmortizataNUD.Enabled = (tipVal != 1) && (Convert.ToInt16(regimAmortizareCB.SelectedValue) != 0);
            ProcentNUD.Enabled = (tipVal != 1) && (Convert.ToInt16(regimAmortizareCB.SelectedValue) != 0);
            DurataAmortizareAniNUD.Enabled = (tipVal != 1) && (Convert.ToInt16(regimAmortizareCB.SelectedValue) != 0);
            DurataAmortizareLuniNUD.Enabled = (tipVal != 1) && (Convert.ToInt16(regimAmortizareCB.SelectedValue) != 0);
            LocFunctionareGB.Enabled = (tipVal != 1);
            ValoriGB.Enabled = (tipVal != 1);

            ///Obiecte de inventar
            ///
            ClasificareCB.Visible = tipVal < 3;
            ClasificareCB1.Visible = tipVal < 3;
            ClasificareL.Visible = tipVal < 3;
            DurataAmortizareGB.Visible = tipVal < 3;
            DurataNormataL.Visible = tipVal < 3;
            MaxL.Visible = tipVal < 3;
            comboBox5.Visible = tipVal < 3;
            comboBox6.Visible = tipVal < 3;
            label5.Visible = tipVal < 3;
            modernizareP.Visible = tipVal < 3;
            //PanaLaL.Visible = tipVal >= 3;
            panaLaLL.Visible = tipVal >= 3;
            ValoriGB.Visible = tipVal < 3;
            ObiectInventarP.Visible = tipVal >= 3;


           

        }

        private void CompusCB_Validating(object sender, CancelEventArgs e)
        {
            if (CompusCB.SelectedValue == null || amixDocumenteBindingSource.Current==null)
                return;
            if (Convert.ToInt16(((DataRowView)amixDocumenteBindingSource.Current)["Compus"]) == Convert.ToInt16(CompusCB.SelectedValue))
                return;
            DataRowView drr = ((DataRowView)amixDocumenteBindingSource.Current);
            if (drr["IDMijlocFix"] == null || drr.IsNew)
                return;
            
            SqlCommand cmd = new SqlCommand("SELECT [IDMFixPrincipal] FROM [AmixAnsamble] WHERE [IDMFixPrincipal] = "+
                ((DataRowView)amixDocumenteBindingSource.Current)["IDMijlocFix"].ToString()+" OR [IDMfixComponenta] = " + ((DataRowView)amixDocumenteBindingSource.Current)["IDMijlocFix"]
                , DeschideConexiune(workConnString));
            Object ret = cmd.ExecuteScalar();
            if (ret != null)
            {
                e.Cancel = true;
                CompusCB.SelectedValue = Convert.ToInt16(((DataRowView)amixDocumenteBindingSource.Current)["Compus"]);
                MessageBox.Show("Atentie: mijlocul fix face parte dintr-un ansamblu si nu se poate schimba tipul!" ,
                        "Eroare",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Stop);
                InchideConexiune(cmd.Connection);
                return;
            }
            InchideConexiune(cmd.Connection);
        }

        private void amixDocumenteBindingSource_CurrentChanged(object sender, EventArgs e)
        {
            eSRPDataSet.AmixDocumente.CompusColumn.DefaultValue = MijloaceFixeRB.Checked ? 0 : 3;
            DataRowView dr = ((DataRowView)amixDocumenteBindingSource.Current);
            if (dr == null)
            {
                MyTrace("DataRowView == null");
                return;
            }
            ESRPDataSet.AmixDocumenteRow adr = dr.Row as ESRPDataSet.AmixDocumenteRow;
            if (adr == null)
            {
                MyTrace("ESRPDataSet.AmixDocumenteRow = null");
                return;
            }
            if (adr.IDTipDocument == 4 || adr.IDTipDocument == 3)
            {
                int ret = amixRegistruBindingSource.Find("IDMijlocFix",adr.IDMijlocFix);
                if (ret != -1)
                {
                    amixRegistruBindingSource.Position = ret;
                    ESRPDataSet.AmixRegistruRow amrr = ((DataRowView)amixRegistruBindingSource.Current).Row as ESRPDataSet.AmixRegistruRow;
                    if (ValoareInventarNUD.Value != amrr.ValoareInventar)
                        ValoareInventarNUD.Value = amrr.ValoareInventar;
                    if (ValoareRamasaNUD.Value != amrr.ValoareInventar - amrr.ValoareAmortizata)
                        ValoareRamasaNUD.Value = amrr.ValoareInventar - amrr.ValoareAmortizata;

                    if (luniAmortizateNUD.Value != amrr.LuniAmortizate)
                        luniAmortizateNUD.Value = amrr.LuniAmortizate;
                    block = true;
                    DurataAmortizareAniNUD.Value = amrr.DurataAmortizare / 12;
                    DurataAmortizareLuniNUD.Value = amrr.DurataAmortizare % 12;
                    block = false;
                }
            }
            tipDocCB.Enabled = dr.IsNew;
            if (adr.IDTipDocument > 2 && adr.IDTipDocument != 4 && adr.IDTipDocument != 3)
            {
                block = true;
                Decimal vid = Decimal.Zero;
                if (valoareInventarTB.Text != String.Empty)
                    vid = Convert.ToDecimal(valoareInventarTB.Text);
                Decimal valnoua =  vid- valoareSuplimentaraNUD.Value;
                if(ValoareInventarNUD.Value!=valnoua)
                    ValoareInventarNUD.Value = valnoua;
                Decimal vam = Decimal.Zero;
                if(ValoareAmortizataNUD.Text!=String.Empty)
                    vam = Convert.ToDecimal(ValoareAmortizataNUD.Text);
                valnoua = ValoareInventarNUD.Value - vam;
                if (ValoareRamasaNUD.Value != valnoua)
                    ValoareRamasaNUD.Value = valnoua;
                block = false;
            }
            
        }

        private void ValoareInventarTB_Validated(object sender, EventArgs e)
        {
            if (valoareInventarTB.Visible == false || valoareInventarTB.Text == String.Empty || Convert.ToDecimal(valoareInventarTB.Text) == Decimal.Zero ||
                Convert.ToDecimal(durataAmortizareNUD.Text) == Decimal.Zero || BlockCorelations || regimAmortizareCB.SelectedValue == null
                || tipDocCB.SelectedValue == null)
                return;

            if (amixDocumenteBindingSource.Current == null)
                return;
            ESRPDataSet.AmixDocumenteRow adr = ((DataRowView)amixDocumenteBindingSource.Current).Row as ESRPDataSet.AmixDocumenteRow;
            /// daca nu s-a modificat nimic
            /// 
            ProcentP.Visible = Convert.ToInt32(regimAmortizareCB.SelectedValue) == 3;
            Decimal ProcAn = Decimal.Zero;
            if(ProcentNUD.Text!=String.Empty)
                ProcAn = Convert.ToDecimal(ProcentNUD.Text);
            Decimal vam = Decimal.Zero;
            if (ValoareAmortizataNUD.Text != String.Empty)
                vam = Convert.ToDecimal(ValoareAmortizataNUD.Text);
            if (Convert.ToInt16(tipDocCB.SelectedValue) == 8)
            {
                //modernizare
                
                adr.ValoareInventar = ValoareInventarNUD.Value + valoareSuplimentaraNUD.Value;
                Decimal amo = Convert.ToDecimal(durataAmortizareNUD.Text) + durataExtindereNUD.Value - luniAmortizateNUD.Value;
                
                switch (Convert.ToInt32(regimAmortizareCB.SelectedValue))
                {
                    case 0:
                        adr.AmortizareAn = Decimal.Zero;
                        adr.AmortizareLuna = Decimal.Zero;
                        break;
                    case 1:
                        adr.AmortizareAn = ((adr.ValoareInventar - adr.ValoareAmortizata) / amo) * 12;
                        adr.AmortizareLuna = ((adr.ValoareInventar - vam) / amo);
                        break;
                    case 2: //degresiv
                        adr.AmortizareAn = ((adr.ValoareInventar - vam) / Convert.ToDecimal(durataAmortizareNUD.Text)) * GetCoefDegresiv(amo) * 12;
                        adr.AmortizareLuna = ((adr.ValoareInventar - vam) / Convert.ToDecimal(durataAmortizareNUD.Text)) * GetCoefDegresiv(amo);
                        break;
                    case 3: ///accelerat
                        ///
                        adr.AmortizareAn = ((adr.ValoareInventar - vam) * ProcAn / 100);
                        adr.AmortizareLuna = ((adr.ValoareInventar - vam) * ProcAn / 100) / 12;
                        break;

                }
                adr.AmortizareAn = Decimal.Round(adr.AmortizareAn, 2);
                AmortizareAnTB.Text = adr.AmortizareAn.ToString();
                adr.AmortizareLuna = Decimal.Round(adr.AmortizareLuna, 2);
                AmortizareLunaTB.Text = adr.AmortizareLuna.ToString(); 

            }
            else
            {
                switch (Convert.ToInt32(regimAmortizareCB.SelectedValue))
                {
                    case 0:
                        adr.AmortizareAn = Decimal.Zero;
                        adr.AmortizareLuna = Decimal.Zero;
                        break;
                    case 1:
                        adr.AmortizareAn = ((adr.ValoareInventar - vam) / Convert.ToDecimal(durataAmortizareNUD.Text)) * 12;
                        adr.AmortizareLuna = ((adr.ValoareInventar - vam) / Convert.ToDecimal(durataAmortizareNUD.Text));
                        break;
                    case 2: //degresiv
                        adr.AmortizareAn = ((adr.ValoareInventar - vam) / Convert.ToDecimal(durataAmortizareNUD.Text)) * GetCoefDegresiv(Convert.ToDecimal(durataAmortizareNUD.Text)) * 12;
                        adr.AmortizareLuna = ((adr.ValoareInventar - vam) / Convert.ToDecimal(durataAmortizareNUD.Text)) * GetCoefDegresiv(Convert.ToDecimal(durataAmortizareNUD.Text));
                        break;
                    case 3: ///accelerat
                        ///
                        adr.AmortizareAn = ((adr.ValoareInventar - vam) * ProcAn / 100);
                        adr.AmortizareLuna = ((adr.ValoareInventar - vam) * ProcAn / 100) / 12;
                        break;
                }
                adr.AmortizareAn = Decimal.Round(adr.AmortizareAn,2);
                AmortizareAnTB.Text = adr.AmortizareAn.ToString();
                adr.AmortizareLuna = Decimal.Round(adr.AmortizareLuna, 2);
                AmortizareLunaTB.Text = adr.AmortizareLuna.ToString(); 

            }            

        }

        private void button1_Click(object sender, EventArgs e)
        {
            MijlocFixRezumatFrm frm = new MijlocFixRezumatFrm(ModuleInfo, amixRegistruBindingSource, -1,MijloaceFixeRB.Checked);
            frm.SelectionAddOn = true;
            frm.ShowDialog();
            if (frm.selectedDataRow != null)
            {
                ESRPDataSet.AmixRegistruRow pr = frm.selectedDataRow.Row as ESRPDataSet.AmixRegistruRow;
                amixRegistruBindingSource.Position = amixRegistruBindingSource.Find("IDMijlocFix", pr.IDMijlocFix);
                nrInventarTB.Text = pr.NrInventar;
                nrInventarTB.Focus();
            }
           
        }

        private void MijloaceFixeRB_CheckedChanged(object sender, EventArgs e)
        {
            SqlConnection con = DeschideConexiune(workConnString);
            this.amixDocumenteTableAdapter.Connection = con;
            if (codDoc != -1)
            {
                //deschide un singur document
                this.amixDocumenteTableAdapter.FillByOne(this.eSRPDataSet.AmixDocumente, ModuleInfo.CodUnitate, codDoc);
            }
            else
                this.amixDocumenteTableAdapter.Fill(this.eSRPDataSet.AmixDocumente, ModuleInfo.CodUnitate,
                    (short)(MijloaceFixeRB.Checked ? 0 : 3), (short)(MijloaceFixeRB.Checked ? 2 : 5));
            amixRegistruTableAdapter.Connection = con;
            amixRegistruTableAdapter.Fill(eSRPDataSet.AmixRegistru, ModuleInfo.CodUnitate, (short)(MijloaceFixeRB.Checked ? 0 : 3), (short)(MijloaceFixeRB.Checked ? 2 : 5));
            InchideConexiune(con);
            CompusCB.SelectedIndex = MijloaceFixeRB.Checked ? 0 : 3;
            CompusCB_SelectedIndexChanged(sender, e);
        }

        private void denumireTB_TextChanged(object sender, EventArgs e)
        {
            DenumireLungimeLabel.Text = denumireTB.Text.Length.ToString() + " din 250";
        }

        private void comisiaRecTextBox_TextChanged(object sender, EventArgs e)
        {
            ObservatiiLungimeLabel.Text = comisiaRecTextBox.Text.Length.ToString() + " din 250";
        }

        private void DepartamenteB_Click(object sender, EventArgs e)
        {
            FrmMainMdi frm = this.MdiParent as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;
            
            String numeClasa = "ERPForms.DepartamenteFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmTreeRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                   new object[] { ModuleInfo }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmTreeRezumat;
                //newFrm.MdiParent = frm;
                newFrm.SelectionAddOn = true;
                newFrm.ReadOnly = true;
                newFrm.ShowDialog();
                if (newFrm.selectedDataRow!=null && newFrm.selectedDataRow.Row != null)
                {
                    //ESRPDataSet.DepartamenteRow dr = newFrm.selectedDataRow.Row as ESRPDataSet.DepartamenteRow;
                    int poz = departamenteBindingSource.Find("IDDepartament", newFrm.selectedDataRow["IDDepartament"]);
                    if (poz != -1)
                        departamenteBindingSource.Position = poz;
                }
            }
        }

        private void ObjValoareNUD_ValueChanged(object sender, EventArgs e)
        {
            if( TotalValoareNUD.Value!=(ObjValoareNUD.Value*CantitateOINUD.Value))
                TotalValoareNUD.Value=ObjValoareNUD.Value*CantitateOINUD.Value;
        }

        private void nrInventarTB_Leave(object sender, EventArgs e)
        {
            if (amixDocumenteBindingSource.Current == null)
                return;
            ESRPDataSet.AmixDocumenteRow adr = ((DataRowView)amixDocumenteBindingSource.Current).Row as ESRPDataSet.AmixDocumenteRow;
            Int16 tipDoc = adr.IDTipDocument;

            ESRPDataSet.AmixRegistruRow arr = ((DataRowView)amixRegistruBindingSource.Current).Row as ESRPDataSet.AmixRegistruRow;
            if (arr == null)
                return;


            int poz = amixRegistruBindingSource.Position;
            if (arr.NrInventar != nrInventarTB.Text)
            {
                poz = amixRegistruBindingSource.Find("NrInventar", nrInventarTB.Text);

                if (poz == -1 && tipDoc > 2)
                    return;

                amixRegistruBindingSource.Position = poz;
                arr = ((DataRowView)amixRegistruBindingSource.Current).Row as ESRPDataSet.AmixRegistruRow;
            }


            if (poz == -1)
            {
                denumireTB.Text = String.Empty;
                ClasificareCB.SelectedValue = 0; //rdCurReg["IDClasificare"];
                ClasificareCB1.SelectedValue = 0; //rdCurReg["IDClasificare"];
                durataAmortizareNUD.Text = "0";
            }
            else
            {
                if(denumireTB.Text != arr.Denumire)
                    denumireTB.Text = arr.Denumire;
                if(Convert.ToInt32(ClasificareCB.SelectedValue) != arr.IDClasificare)
                    ClasificareCB.SelectedValue = arr.IDClasificare;
                if (Convert.ToInt32(ClasificareCB1.SelectedValue) != arr.IDClasificare)
                    ClasificareCB1.SelectedValue = arr.IDClasificare;
                if (Convert.ToInt32(regimAmortizareCB.SelectedValue) != arr.RegimAmortizare)
                    regimAmortizareCB.SelectedValue = arr.RegimAmortizare;
                if (durataAmortizareNUD.Text != arr.DurataAmortizare.ToString())
                    durataAmortizareNUD.Text = arr.DurataAmortizare.ToString();
                if (ValoareInventarNUD.Value != arr.ValoareInventar)
                    ValoareInventarNUD.Value = arr.ValoareInventar;
                if (ObjValoareNUD.Value != arr.ValoareInventar)
                    ObjValoareNUD.Value = arr.ValoareInventar;
                if (ValoareRamasaNUD.Value != arr.ValoareInventar - arr.ValoareAmortizata)
                    ValoareRamasaNUD.Value = arr.ValoareInventar - arr.ValoareAmortizata;
                if (ValoareAmortizataNUD.Text != arr.ValoareAmortizata.ToString())
                    ValoareAmortizataNUD.Text = arr.ValoareAmortizata.ToString();
                if (Convert.ToInt16(CompusCB.SelectedValue) != arr.Compus)
                    CompusCB.SelectedValue = arr.Compus;
                if (luniAmortizateNUD.Value != arr.LuniAmortizate)
                    luniAmortizateNUD.Value = arr.LuniAmortizate;
                DateTime dIesire = arr.DataIesire;
                if (CantitateOINUD.Value != arr.CantitateOI)
                    CantitateOINUD.Value = arr.CantitateOI;
                if (TotalValoareNUD.Value != CantitateOINUD.Value * ObjValoareNUD.Value)
                    TotalValoareNUD.Value = CantitateOINUD.Value * ObjValoareNUD.Value;
                if (!arr.IsCategorieNull() && categorieTB.Text != arr.Categorie)
                    categorieTB.Text = arr.Categorie;
                if (valoareInventarTB.Text != arr.ValoareInventar.ToString())
                    valoareInventarTB.Text = arr.ValoareInventar.ToString();
                if (AmortizareAnTB.Text != arr.AmortizareAn.ToString())
                    AmortizareAnTB.Text = arr.AmortizareAn.ToString();
                if (AmortizareLunaTB.Text != arr.AmortizareLuna.ToString())
                    AmortizareLunaTB.Text = arr.AmortizareLuna.ToString();
                if (ValoareAmortizataNUD.Text != arr.ValoareAmortizata.ToString())
                    ValoareAmortizataNUD.Text = arr.ValoareAmortizata.ToString();
                //if ((iDSursaFinantareComboBox.SelectedValue==null) || (Convert.ToInt16(iDSursaFinantareComboBox.SelectedValue) != arr.IDSursaFinantare))
                //    iDSursaFinantareComboBox.SelectedValue = arr.IDSursaFinantare;
                if (adr.IsIDMijlocFixNull() || adr.IDMijlocFix != arr.IDMijlocFix)
                    adr.IDMijlocFix = arr.IDMijlocFix;
            } 

        }
  
    }
    [Serializable]
    public class RegimuriAmortizare
    {
        public RegimuriAmortizare(String nume, Int16 tag)
        {
            _Name = nume;
            _Tag = tag;
        }

        private String _Name = String.Empty;
        [System.ComponentModel.Bindable(true)]
        public String Name
        {
            get
            {
                return _Name;
            }
            set
            {
                _Name = value;
            }
        }
        private Int16 _Tag = 0;
        [System.ComponentModel.Bindable(true)]
        public Int16 Tag
        {
            get
            {
                return _Tag;
            }
            set
            {
                _Tag = value;
            }
        }
    }
}
